<?php
$set_letters_obj = new SetLetters();
$config_obj = new GeneralConfig();

function show_set_letters(){
	global $set_letters_obj;
	$letters = $set_letters_obj->find("all");
	
	include_once 'views/set_letters.html.php';
}

function edit_letters(){
	global $set_letters_obj, $set_letter_config, $KToolBar;
	$action = "Edit Letter";
	$letter = $set_letters_obj->find((int)$_GET['lid']);
	
	include_once 'views/create_or_edit_letter.html.php';
}

function create_letters(){
	global $set_letters_obj, $set_letter_config, $KToolBar;
	$action = "Create Letter";
	
	include_once 'views/create_or_edit_letter.html.php';
}

function save_letter(){
	global $set_letters_obj, $notice;
	if($_POST['letter']['identifier'] == "" OR $_POST['letter']['msg_subject'] == "" OR $_POST['letter']['msg_body'] == ""){
		$notice['error'] = 1;
		$notice['msg'] = "All the fields are required";
	}
	else {
		if(!empty($_POST['lid'])) $identifier = array("id" => $_POST['lid']);
		else $identifier = "";
		$notice = $set_letters_obj->insert_or_update($_POST['letter'], $identifier);
	}
}

function show_general_config(){
	global $config_obj, $KToolBar;
	$config = $config_obj->find(1);
//	echo $config_obj->admin_email;
	include_once 'views/general_config.html.php';
}

function save_config(){
	global $config_obj,$notice;
	$notice = $config_obj->insert_or_update($_POST['config'], array("id"=>1));
}
?>